package map;

import java.util.Comparator;
import java.util.TreeMap;

public class Demo6 {
    public static void main(String[] args) {
        TreeMap<Student,String>tm = new TreeMap<>(new Comparator<Student>() {
            @Override
            public int compare(Student o1, Student o2) {
                int result = o1.getAge() - o2.getAge();
                result =result==0? o1.getName().compareTo(o2.getName()): result;
                return  result;
            }
        });
        Student s1 = new Student("zhangsang",28);
        Student s2 = new Student("lisi",38);
        Student s3 = new Student("wanglaowu",58);
        tm.put(s1,"湖南");
        tm.put(s2,"湖北");
        tm.put(s3,"上海");

        tm.forEach(
                (Student key , String value )->{
                    System.out.println(key+"----"+value);
                }
        );
    }
}
